#include "stdafx.h"
#include "TextEditExample.h"

#include "hwinapplication.h"
#include "hwinform.h"
#include "hwinmenu.h"
#include "hwinstdctrls.h"
#include <iostream>

using namespace harlinn::windows;

class TextEditForm : public Form
{
    std::shared_ptr<MemoEdit> edit;
public:
    typedef Form Base;
    TextEditForm();
protected:
    virtual void DoOnInitialize();
    virtual void DoOnSize(Message& message);
    virtual void DoOnShown();
};


TextEditForm::TextEditForm()
    : Base()
{
    SetText(L"Text Edit example");
    SetSize(300,300);
}

void TextEditForm::DoOnInitialize()
{
    Base::DoOnInitialize(); 
    auto self = As<TextEditForm>();
    edit = make_control<MemoEdit>(self);
}


void TextEditForm::DoOnSize(Message& message)
{
    harlinn::windows::Rectangle clientRect = GetClientRect();
    edit->MoveWindow(0,0,clientRect.Width(),clientRect.Height());
}


void TextEditForm::DoOnShown()
{
    Base::DoOnShown();
    edit->Append(L"Append");
    edit->AppendLine(L"AppendLine");
    edit->Append(L"Append");
    edit->AppendLine(L"AppendLine");
}


int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);
    try
    {
        auto application = make_component<Application>();
        auto form = make_control<TextEditForm>();
        
        auto result = application->Run(form);

        return result;
    }
    catch(std::exception& exc)
    {
        std::cout << exc.what() << std::endl;
    }
    catch(...)
    {
        std::cout << "Unknown exception" << std::endl;    
    }
    return 0;
}



